package main

import "fmt"

// 方法 （指结构体对应的函数）
func main() {
	testCopyValue01()
	//testMethod02()
}

// testCopyValue01
//
//	@Description: 值拷贝
func testCopyValue01() {
	var p Person
	p.Name = "zhangsan"
	p.sayMyName()       //print= zhangsan
	fmt.Println(p.Name) //zhangsan

	//值传递
	p.changeMyName("WANGWU")
	p.sayMyName() //print= zhangsan

}
func testMethod02() {
	var p Person = Person{"王小二", 18, 6800.00}
	p.speak()                //王小二 is 00father good man
	p.cal()                  //王小二 算出来了= 500500
	p.count(8000)            //王小二 算出来了= 32004000
	res := p.sum(1200, 1800) //sum= 3000
	fmt.Println(res)         //3000
}

type Person struct {
	Name string
	Age  int
	sal  float64
}

func (p Person) sayMyName() {
	fmt.Println("my name is :", p.Name)
}

func (p Person) changeMyName(name string) {
	p.Name = name
	fmt.Println("changeMyName=", p.Name) //changeMyName= WANGWU
}

func (p Person) speak() {
	fmt.Println(p.Name, "is 00father good man")
}
func (p Person) cal() int {
	var total int
	for i := 1; i <= 1000; i++ {
		total += i
	}
	fmt.Println(p.Name, "算出来了=", total)
	return total

}

func (p Person) count(num int) int {
	var total int
	for i := 1; i <= num; i++ {
		total += i
	}
	fmt.Println(p.Name, "算出来了=", total)
	return total

}

func (p Person) sum(n1 int, n2 int) (res int) {
	res = n1 + n2
	fmt.Println("sum=", res)
	return

}
